$(document).ready(function () {

	function showItem() {
		if ($('div.item:not(.showup)').length) {
			$('div.item:not(.showup):first').show().addClass('showup');
			 setTimeout(showItem, 150);
		}
	}

	function playPage() {
		$('#ladder').show().addClass('showup');
		showItem();
	}
	function clearPage() {
		$('#ladder').hide().removeClass('showup');
		$('div.item').hide().removeClass('showup');
	}

	var wh = $(window).height();
	if (wh <= 480) {
		$('#page-1').find('.page-title').hide();
	}

	var p0 = document.getElementById('page-0');
	var p1 = document.getElementById('page-1');
	var hp0 = new Hammer(p0);
	hp0.get('swipe').set({ direction: Hammer.DIRECTION_VERTICAL });
	hp0.on('swipeup', function () {
		$('#page-0').slideUp().next().slideDown();
		playPage();
	});
	var hp1 = new Hammer(p1);
	hp1.get('swipe').set({ direction: Hammer.DIRECTION_VERTICAL });
	hp1.on('swipedown', function () {
		$('#page-1').slideUp().prev().slideDown();
		clearPage();
	});


	$('div.item').find('a').click(function (e) {
		e.preventDefault();
		var $this = $(this);
		var clickHref = $this.attr('href');
		$('#page-1').slideUp();
		$(clickHref).slideDown();
		clearPage();
	});

	$('a.return, a.back').click(function (e) {
		e.preventDefault();
		$(this).parent().slideUp();
		$('#page-1').slideDown();
		playPage();
	});

});